Index: trunk/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 20712)
+++ trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 20714)
@@ -213,4 +213,19 @@
     int numCols = ro1->image->numCols, numRows = ro1->image->numRows; // Image dimensions
 
+    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
+
+    {
+        psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for backgroun
+        if (!psImageBackground(bg, NULL, ro1->image, ro1->mask, maskVal, rng)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics.");
+            psFree(bg);
+            psFree(rng);
+            goto MATCH_ERROR;
+        }
+        threshold = bg->robustMedian + threshold * bg->robustStdev;
+        psFree(bg);
+        psFree(rng);
+    }
+
     memCheck("start");
 
@@ -270,10 +285,8 @@
                 // Get backgrounds
                 psStats *bgStats = psStatsAlloc(BG_STAT); // Statistics for background
-                psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); // Random number generator
                 psVector *buffer = NULL;// Buffer for stats
                 if (!psImageBackground(bgStats, &buffer, ro1->image, ro1->mask, maskVal, rng)) {
                     psError(PS_ERR_UNKNOWN, false, "Unable to measure background of image 1.");
                     psFree(bgStats);
-                    psFree(rng);
                     psFree(buffer);
                     goto MATCH_ERROR;
@@ -283,5 +296,4 @@
                     psError(PS_ERR_UNKNOWN, false, "Unable to measure background of image 2.");
                     psFree(bgStats);
-                    psFree(rng);
                     psFree(buffer);
                     goto MATCH_ERROR;
@@ -289,5 +301,4 @@
                 float bg2 = psStatsGetValue(bgStats, BG_STAT); // Background for image 2
                 psFree(bgStats);
-                psFree(rng);
                 psFree(buffer);
 
@@ -423,4 +434,6 @@
         }
     }
+    psFree(rng);
+    rng = NULL;
     psFree(region);
     region = NULL;
@@ -473,4 +486,5 @@
     psFree(stamps);
     psFree(weight);
+    psFree(rng);
     return false;
 }
Index: trunk/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 20712)
+++ trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 20714)
@@ -301,5 +301,5 @@
                     fluxList->n = index;
 
-                    goodStamp = true;
+                    goodStamp = (fluxStamp > threshold) ? true : false;
                 } else {
                     psTrace("psModules.imcombine", 9, "No sources in subregion %d", i);
