This patch adds a filter argument to uiTemplateID functions, which can be used show it only a subset of the ID's.
Currently the only filter is AVAILABLE - used for selecting objects in the current scene (but could be used elsewhere).
Others could be added (LOCAL/LIBRARY...) as needed.
Submitting as a diff since this is a bit more intrusive than I'd have liked, so Bastien might want to check.
Note that I did consider adding a poll function to scene.objects.active which is correct but this will be too slow in practice (every item in the search popup having to check it's scene membership).