How can I count distinct columns inside a group?
I'm pretty sure that this will work for you.  I don't have a MySQL instance available to me to check my syntax, but this should get you close.

SELECT gender, COUNT(id_number)
FROM (  SELECT DISTINCT
            name
            , surname
            , id_number
            , gender
        FROM table1
        ) AS D
GROUP BY gender;