def GetChildNodesWhereTrue(node_id, tree, stop_function):
    """walk down in tree and stop where stop_function is true

    The walk finishes at the leaves.

    returns a list of tuples of nodes and distance.
    """

    result = []

    def __getChildNodes(node_id, distance):

        node = tree.node(node_id)

        distance += node.data.branchlength

        if not node.succ:
            result.append((node_id, distance))
        elif stop_function(node_id):
            result.append((node_id, distance))
        else:
            for x in node.succ:
                __getChildNodes(x, distance)

    node = tree.node(node_id)
    __getChildNodes(node_id, -node.data.branchlength)

    return result