def contains_two_pairs(password: str) -> bool:
    """
    Return True if the password contains two distinct pairs of matching characters, or False if it
    does not.
    """
    prev = ""
    count_pairs = 0
    for letter in password:
        if letter == prev:
            count_pairs += 1
            prev = ""
        else:
            prev = letter
    return count_pairs >= 2