You should create a filtered graph first. You can do:
u = GraphView(g, efilt=rel_need)
where rel_need is a Boolean property map, where rel_need[e] == True
means that the edge is not filtered out.
You can then proceed to do the DFS search with the graph u
, and the edges for which rel_need[e] == False
will be ignored.