md_build_ref_def_hashtable: Fix variable conflict. By copy&paste error, we have used two nested loops to use the same iterator.