Optimal consensus-based clock synchronisation algorithm in wireless sensor network by selective averaging