Mortgage lenders favor loan applicants who show a steady, predictable pattern of handling their credit card accounts and other debts. When you suddenly close an account you break the pattern that you have established in the past several years, and your credit score likely will decline.
Closing the account now could also hurt your chances of getting a mortgage later because it would increase your debt-to-credit-limit ratio - a figure that represents the percentage of available credit that you have actually used. Lenders prefer borrowers with low debt ratios. Closing the account would automatically push your personal ratio higher even if you didn't put any new charges on the cards. Because of these factors, it would be better to close any credit card accounts that you are not using after you apply for the new mortgage - not before.
Much more can also be done to improve your credit score.