(match_ids): New arg "direction". Callers changed.