Study of the rare decay K± → π±γγ in the NA48/2 and NA62 experiments at CERN