The exercise sentence is in reported speech, also called 'indirect speech/question'. Therefore, the correct answer is B: 'My mother asked what the matter was with me'. The direct question could have been: 'What is the matter with you?'. Your last example is fine.