diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c
index eb003d82b385e3c9df98c971a200703625e905c7..9ce2bc8a896b488442b980447dcf7c18bb665d54 100644
--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -1992,7 +1992,31 @@ static void decide_kf_ymode_entropy(VP8_COMP *cpi)
 
 }
 #endif
+static segment_reference_frames(VP8_COMP *cpi)
+{
+    VP8_COMMON *oci = &cpi->common;
+    MODE_INFO *mi = oci->mi;
+    int ref[MAX_MB_SEGMENTS]={0};
+    int i,j;
+    int mb_index=0;
+    MACROBLOCKD *const xd = & cpi->mb.e_mbd;
+
+    for (i = 0; i < oci->mb_rows; i++)
+    {
+        for (j = 0; j < oci->mb_cols; j++, mb_index++)
+        {
+            ref[mi[mb_index].mbmi.segment_id]|=(1<<mi[mb_index].mbmi.ref_frame);
+        }
+        mb_index++;
+    }
+    for (i = 0; i < MAX_MB_SEGMENTS; i++)
+    {
+        enable_segfeature(xd,i,SEG_LVL_REF_FRAME);
+        set_segdata( xd,i, SEG_LVL_REF_FRAME, ref[i]);
+    }
 
+
+}
 void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
 {
     int i, j;
@@ -2066,6 +2090,8 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
 
         vp8_write_bit(bc, (xd->update_mb_segmentation_data) ? 1 : 0);
 
+        segment_reference_frames(cpi);
+
         if (xd->update_mb_segmentation_data)
         {
             signed char Data;
diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 639d53dbc5600176ecd0858b849413513b2519eb..779577f2d305e5435a7d6216f7acfb65f67aa51d 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -541,6 +541,20 @@ static void init_seg_features(VP8_COMP *cpi)
     // All other frames if segmentation has been enabled
     else if ( xd->segmentation_enabled )
     {
+        int i;
+
+        // clears prior frame seg lev refs
+        for (i = 0; i < MAX_MB_SEGMENTS; i++)
+        {
+            // only do it if the force drop the background stuff is off
+            if(!segfeature_active(xd, i, SEG_LVL_MODE))
+            {
+                disable_segfeature(xd,i,SEG_LVL_REF_FRAME);
+                set_segdata( xd,i, SEG_LVL_REF_FRAME, 0xffffff);
+            }
+        }
+
+
         // First normal frame in a valid gf or alt ref group
         if ( cpi->common.frames_since_golden == 0 )
         {