@staticmethod
def filterContactsByName(contacts, nameA, nameB, mapindex):
    """Returns contacts, when their key is included in nameA and nameB."""
    filtered = []
    for c in contacts:
        add = False
        try:
            prop1 = c.key1[mapindex]
            prop2 = c.key2[mapindex]
        except IndexError:
            filtered.append(c)
            continue
        if nameA.lower() != u'all' and nameB.lower() != u'all':
            splitA = nameA.split(u',')
            splitB = nameB.split(u',')
            if prop1 in splitA and prop2 in splitB:
                add = True
        elif nameA.lower() != u'all' and nameB.lower() == u'all':
            splitA = nameA.split(u',')
            if prop1 in splitA:
                add = True
        elif nameA.lower() == u'all' and nameB.lower() != u'all':
            splitB = nameB.split(u',')
            if prop2 in splitB:
                add = True
        else:
            add = True
        if add:
            filtered.append(c)
    return filtered
