def filter_related_term_list(hpo_counts, related_terms, min_diff):
    """
    Retain pairs of related terms with sample size differences < min_diff
    """

    filtered_pairs = []

    for termA, termB in related_terms:
        
        countA = hpo_counts.get(termA, 0)
        countB = hpo_counts.get(termB, 0)
        
        if abs(countA - countB) < min_diff:
            filtered_pairs.append((termA, termB))

    return filtered_pairs