diff --git a/JEC/interface/JMEmatching.h b/JEC/interface/JMEmatching.h
index d8d3270538c7468589cc7f7dcf87657734942473..cfc63ad8259af83201b84dd051d0e47ff4a9535e 100644
--- a/JEC/interface/JMEmatching.h
+++ b/JEC/interface/JMEmatching.h
@@ -82,6 +82,7 @@ template<typename RecContainer = std::vector<RecJet>,
         match_its.reserve(min(nRec,nGen));
         while (!candidates.empty()) {
             auto& [iRec, iGen] = candidates.top();
+            candidates.pop();
 
             // skip already matched objects
             if (matchedRec.at(iRec)) continue;
@@ -95,7 +96,6 @@ template<typename RecContainer = std::vector<RecJet>,
             advance(gen_it, iGen);
 
             match_its.push_back( make_pair(rec_it, gen_it) );
-            candidates.pop();
         }
 
         // 5) fill the unmatched entries