An accurate cluster selection function for the J-PAS narrow-band wide-field survey