Topological expansion for SO_N and Sp_2N gauge theories