Generally, individuals who are resident aliens and non-resident aliens working in the United States (U.S.) on work visas are subject to Medicare and Social Security taxes. However, there are exceptions for non-resident aliens who have A, D, F, J, M, or Q, visas. Click the following link Aliens Employed in the US - Social Security It explains the exceptions and provide links to Totalization Agreements and International Treaties the U.S. has with various countries.
Usually, excess Social Security taxes are taken as a credit on the Form 1040 that may result in a larger refund or reduce any taxes due. However, this only applies if there are multiple employers, and your total wages exceed the Social Security threshold. There isn't a wage limitation for Medicare.
If you are not subject to the Medicare and Social Security taxes after referring to the Internal Revenue Service link that is provided, then your employer is required to make the necessary adjustments on their payroll tax return and issue a corrected Form W-2 once you provide the necessary substantiation. They are also required to refund you any amounts that were erroneously withheld.