def intersect_trees(tree1, tree2):
    """Shrink two trees to contain only overlapping taxa.

    Parameters
    ----------
    tree1 : skbio.TreeNode
        first tree to intersect
    tree2 : skbio.TreeNode
        second tree to intersect

    Returns
    -------
    tuple of two TreeNodes
        resulting trees containing only overlapping taxa
    """
    taxa1 = [tip.name for tip in tree1.tips()]
    taxa2 = [tip.name for tip in tree2.tips()]
    n1, n2 = len(taxa1), len(taxa2)
    taxa1, taxa2 = set(taxa1), set(taxa2)
    if n1 != len(taxa1) or n2 != len(taxa2):
        raise ValueError('Either tree has duplicated taxa.')
    taxa_lap = taxa1.intersection(taxa2)
    if len(taxa_lap) == 0:
        raise KeyError('Trees have no overlapping taxa.')
    tree1_lap = tree1.shear(taxa_lap)
    tree2_lap = tree2.shear(taxa_lap)
    return (tree1_lap, tree2_lap)