def get_matched_midi_md5(msd_id: str, msd_score_matches: dict):
  """
  Returns the MD5 of the matched MIDI from its MSD id.

  :param msd_id: the MSD id
  :param msd_score_matches: the MSD score dict, use get_msd_score_matches
  :return: the matched MIDI MD5
  """
  max_score = 0
  matched_midi_md5 = None
  for midi_md5, score in msd_score_matches[msd_id].items():
    if score > max_score:
      max_score = score
      matched_midi_md5 = midi_md5
  if not matched_midi_md5:
    raise Exception(f"Not matched {msd_id}: {msd_score_matches[msd_id]}")
  return matched_midi_md5