AMICO: optimized detection of galaxy clusters in photometric surveys