Roger Federer survived a scare to reach the final of the Brisbane International with a 6-3 6-7 (3-7) 6-3 win over Jeremy Chardy.