def ExtractContactResidues(distMat, threshold=5):
    """returns pairs of residues in contacts (threshold).
    Input: distance matrix and threshold (default = 5)
    Output : list of lists which contain the residues in contacts.
    """

    contacts = []

    for i in range(distMat.shape[0]):
        for j in range(i + 1, distMat.shape[1]):
            if distMat[i, j] <= threshold:
                contacts.append([i, j])

    return contacts