This is a situation where there are two choices, but you might consider it a specific case of a situation where there are N choices. I would then ask, how would you create a filter with N choices, and then apply N=2.
The benefit of thatthis approach is that if ever you ever want or need to include other genders, you don't have to change your filter allowance. Also, it provides greater consistency with other filters that have N choices.
How about just a list of checkboxes?
Filter by gender:
[x] Male
[x] Female
They can be both on, or one of them can be on. The application should make sure that you cannot uncheck the last option, as it would result in a situation where all items are filtered out.
If ever you need to expand it later:
Filter by gender:
[ ] Male
[x] Female
[x] Other
[x] Not specified
The only downside is that it may require more space. Typically, I would advise you to place your filters in a column rather than in a row.