Make filter_leaves() context-safe

It looks like this function is only used in get_pre_choices(), and it
would return the wrong result because of a missing ensure_context().